package com.assets.Adapter;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.assets.R;
import com.assets.bean.AddRepairs_bean1;
import com.assets.newNHF.util.LogUtils;
import com.bumptech.glide.Glide;

import java.util.List;

/**
 * Created by Administrator on 2019/5/10.
 */

public class Addrepairs_Adapter_new extends ArrayAdapter {
    private Dialog dialog;

    private String state;
    public Addrepairs_Adapter_new(Context context, int resource, List<AddRepairs_bean1> objects, String state) {

        super(context, resource, objects);
        this.state = state;

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {


        final AddRepairs_bean1 linkeMain = (AddRepairs_bean1) getItem(position);
        final View view = LayoutInflater.from(getContext()).inflate(R.layout.addrepairs_item_new, null);
//        if (state.equals("领用")) {
//            TextView baofei = view.findViewById(R.id.baofei);
//            baofei.setVisibility(View.GONE);
//        }
        TextView jifang = view.findViewById(R.id.jifang);
        TextView jigui = view.findViewById(R.id.jigui);
//        TextView Category_tv = (TextView) view.findViewById(R.id.Category_tv);
        ImageView Asset_img = (ImageView) view.findViewById(R.id.Asset_img);
        TextView Asset_name = (TextView) view.findViewById(R.id.Asset_name);
        TextView Section = (TextView) view.findViewById(R.id.Section);
        TextView Code_number = (TextView) view.findViewById(R.id.Code_number);
        TextView Custodian = (TextView) view.findViewById(R.id.Custodian);
        TextView Model = (TextView) view.findViewById(R.id.Model);
        TextView rfid = (TextView) view.findViewById(R.id.rfid_tv);
        TextView remark = (TextView) view.findViewById(R.id.remark);
        TextView Category = (TextView) view.findViewById(R.id.Category);
        TextView status = (TextView) view.findViewById(R.id.status);
        if (!TextUtils.isEmpty(linkeMain.getAsset_img())) {
            Glide.with(getContext()).load(linkeMain.getAsset_img()).into(Asset_img);
        }
        jifang.setText(linkeMain.getJifan());
        jigui.setText(linkeMain.getJigui());
        rfid.setText(linkeMain.getRfid());
        Asset_name.setText(linkeMain.getAsset_name());
//        Category_tv.setText(linkeMain.getCategory_tv());
        Section.setText(linkeMain.getSection());
//        remark.setText(linkeMain.getRemark());
        Code_number.setText(linkeMain.getCode_number());
        Custodian.setText(linkeMain.getCustodian());
        Model.setText(linkeMain.getModel());
        Category.setText(linkeMain.getCategory());
//        if (TextUtils.isEmpty(linkeMain.getStatus())) {
//            status.setText("");
//        } else if (linkeMain.getStatus().equals("0")) {
//            status.setText("待维修");
//        } else if (linkeMain.getStatus().equals("1")) {
//            status.setText("已修复");
//        } else if (linkeMain.getStatus().equals("2")) {
//            status.setText("未修复");
//        } else if (linkeMain.getStatus().equals("3")) {
//            status.setText("故障处理");
//        }
        Asset_img.setOnClickListener(v -> {
            if (!TextUtils.isEmpty(linkeMain.getAsset_img())) {
                LogUtils.d(linkeMain.getAsset_img());
                //展示在dialog上面的大图
                dialog = new Dialog(getContext(), R.style.FullActivity);
                WindowManager.LayoutParams attributes = dialog.getWindow().getAttributes();
                attributes.width = WindowManager.LayoutParams.MATCH_PARENT;
                attributes.height = WindowManager.LayoutParams.MATCH_PARENT;
                dialog.getWindow().setAttributes(attributes);
                ImageView imageView = new ImageView(getContext());
                imageView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
                Glide.with(getContext()).load(linkeMain.getAsset_img()).into(Asset_img);
                dialog.setContentView(imageView);
                //大图的点击事件（点击让他消失）
                dialog.show();
                imageView.setOnClickListener(v1 -> dialog.dismiss());
            }
        });
        return view;
    }
}
